package bpm.dao.impl.process;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.process.Link;
import bpm.domain.process.Node;
import bpm.domain.process.ProcessDefinition;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class LinkMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		Link link = new Link();
		
		link.setLinkId(rs.getString("link_id"));
		link.setLinkName(rs.getString("link_name"));
		link.setLinkIndex(rs.getInt("link_index"));
		link.setDescription(rs.getString("description"));
		
		Node from = new Node();
		Node to = new Node();
		
		link.setFrom(from);
		link.setTo(to);
		
		from.setProcessDefinition(new ProcessDefinition(rs.getString("f_procdef_id")));
		from.setId(rs.getString("f_node_id"));
		from.setName(rs.getString("f_name"));
		from.setType(rs.getString("f_type_key"));
		from.setTaskType(rs.getString("f_task_type"));
		from.setReference(rs.getString("f_reference"));
		from.setDescription(rs.getString("f_description"));
		
		to.setProcessDefinition(new ProcessDefinition(rs.getString("t_procdef_id")));
		to.setId(rs.getString("t_node_id"));
		to.setName(rs.getString("t_name"));
		to.setType(rs.getString("t_type_key"));
		to.setTaskType(rs.getString("t_task_type"));
		to.setReference(rs.getString("t_reference"));
		to.setDescription(rs.getString("t_description"));
		
		return link;
	}

}
